﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WAD.WEB.AppCode;
using WAD.DAL;
using WAD.Model;

namespace WAD.WEB.Client.Ajax
{
    /// <summary>
    /// Channel 的摘要说明
    /// </summary>
    public class Channel : AjaxBase
    {
        public override void AjaxMethodDispatch(String identity)
        {
            switch (identity)
            {
                case "getdefaultlist": this.GetDefaultList(); break;
                case "getlist": this.GetList(); break;
            }
        }
        /// <summary>
        /// 获取默认的频道列表
        /// </summary>
        [QD.Web.Ajax.AjaxMethod]
        public void GetDefaultList()
        {
            List<Dictionary<string, object>> list = DaoChannel.GetDefaultList();
            if (list.Count > 0)
            {
                Success(list);
            }
            else
            {
                DataEmpty();
            }
        }


        /// <summary>
        /// 获取频道列表
        /// </summary>
        [QD.Web.Ajax.AjaxMethod]
        public void GetList()
        {
            int pageIndex = Parse.Int("page_index", 1);//当前页

            PageData pg = DaoChannel.GetList(pageIndex, 20,true);

            if (pg.itemCount == 0)
            {
                DataEmpty();
            }
            else
            {
                for (int i = 0; i < pg.table.Rows.Count; i++)
                {
                    pg.table.Rows[i]["url"] = string.Format("{0}/client/index_app.html?is_recommend=1&channel_id={1}", WJXConfig.Path.URL, pg.table.Rows[i]["id"]);
                }
                Success(pg);
            }
        }
    }
}